Imports System.Drawing.Printing
Public Class PrinFormText
    Private PrtSetupDB As New PrintDialog()
    Private WithEvents PrtDocument As New    PrintDocument()
    Private PageSetupDB As New PageSetupDialog()
    Private PrintPreviewDB As New PrintPreviewDialog()
    Private PrinterSettings As New PrinterSettings()

    Private Sub btnPrintSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintSetup.Click
        PageSetupDB.Document = PrtDocument
        PageSetupDB.ShowDialog()
    End Sub

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        PrtSetupDB.Document = PrtDocument
        PrtSetupDB.PrinterSettings = PrinterSettings
        If (PrtSetupDB.ShowDialog() = DialogResult.OK) Then
            PrtDocument.Print()
        End If
    End Sub

    Private Sub PrtDocument_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Handles PrtDocument.PrintPage
        ev.Graphics.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Black, 0, 0)
    End Sub

    Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
        PrintPreviewDB.Document = PrtDocument
        PrintPreviewDB.ShowDialog()

    End Sub
End Class
